<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-全校教师积分查询</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
        <div class="weui_tab_bd">
        	<div class="weui-header bg-blue"> 
		  		<div class="weui-header-left"> <a href="<%=basePath %>/ls/teacher/points" class="icon icon-109 f-white">返回</a> </div>
		    	<h1 class="weui-header-title">全校教师积分查询</h1>
		    </div>
            <div class="searchbar_wrap"></div>
		    <div id="search-content" style="height: 100%;z-index: 10;position:relation;display: none;">
		       <div class="sb-content" style="overflow:scroll;">
		       </div>
		    </div>
            <div class="weui_tab kcfd-list1 hide" id="tab3" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item tab-blue">总览</div>
                    <div class="weui_navbar_item">加分</div>
                    <div class="weui_navbar_item">减分</div>
	            </div>
	            <div class="weui_tab_bd">
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
		            	<div class="point">
		                      <ul>
		                        <li>
		                          <strong class="f-orange totalPoint">0</strong>
		                          <p>总分</p>
		                        </li>
		                        <li>
		                          <strong class="f-red termPoint">0</strong>
		                          <p>本学期</p>
		                        </li>
		                        <li class="last_l">
		                          <strong class="f-red monthPoint">0</strong>
		                          <p>本月度</p>
		                        </li>
		                      </ul>
	                    </div>
	                    <p class="f20 p10">积分详情</p>
		            	<div class="weui_panel_bd">
	                    	<div class="weui_media_box weui_media_small_appmsg">
			                    <div class="weui_cells weui_cells_access" id="totalList">
			                   </div>
			                 </div>  
			            </div>
						<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
		            	<div class="point">
		                      <ul>
		                        <li>
		                          <strong class="f-orange totalPoint">0</strong>
		                          <p>总分</p>
		                        </li>
		                        <li>
		                          <strong class="f-red termPoint">0</strong>
		                          <p>本学期</p>
		                        </li>
		                        <li class="last_l">
		                          <strong class="f-red monthPoint">0</strong>
		                          <p>本月度</p>
		                        </li>
		                      </ul>
	                    </div>
	                    <p class="f20 p10">积分详情</p>
		            	<div class="weui_panel_bd">
	                    	<div class="weui_media_box weui_media_small_appmsg">
			                    <div class="weui_cells weui_cells_access" id="jiaList">
			                   </div>
			                 </div>  
			            </div>
						<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
			        <div class="weui_panel weui_tab_bd_item qingjia mt0">
				        	<div class="point">
		                      <ul>
		                        <li>
		                          <strong class="f-orange totalPoint">0</strong>
		                          <p>总分</p>
		                        </li>
		                        <li>
		                          <strong class="f-red termPoint">0</strong>
		                          <p>本学期</p>
		                        </li>
		                        <li class="last_l">
		                          <strong class="f-red monthPoint">0</strong>
		                          <p>本月度</p>
		                        </li>
		                      </ul>
	                    </div>
	                    <p class="f20 p10">积分详情</p>
		            	<div class="weui_panel_bd">
	                    	<div class="weui_media_box weui_media_small_appmsg">
			                    <div class="weui_cells weui_cells_access" id="jianList">
			                   </div>
			                 </div>  
			            </div>
						<div class="dropload-down">
				        	<div class="loadData dropload-hasData">点击加载更多数据...</div>
				        </div>
			        </div>
	            </div>
	        </div>
	      </div> 
      </div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
   var totalPage = 0, jiaPage = 0, jianPage = 0;
   var totalRows = 10, jiaRows = 10, jianRows = 10;
   var keyId;
   $(function(){
	   $('.searchbar_wrap').searchBar({
			cancelText: "取消",
			searchText: '请输入教师姓名',
			onfocus: function(value) {
				$("#search-content").show();
				$("#tab3").hide();
			},
			onblur: function(value) {
			},
			input: function(value) {
				queryItem(value);
			},
			onsubmit: function(value) {
				queryItem(value);
			},
			oncancel: function() {
				$("#search-content").hide();
				$("#tab3").show();
				$(".sb-content").html('');
			},
			onclear: function() {
				$(".sb-content").html('');
				$("#search-content").hide();
				$("#tab3").hide();
			}
		});
	    $('#tab3').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
	    $("#tab3 .weui_navbar_item").click(function() {
	    	var index = $(this).index();
	    	if(index == 0) totalRoutine();
	    	else if(index == 1) jiaRoutine();
	    	else if(index == 2) jianRoutine();
	    })
	    $(".dropload-down").on("click", ".dropload-hasData", function() {
	    	var index = $(this).closest(".weui_tab_bd_item").index();
	    	if(index == 0) totalRoutine();
	    	else if(index == 1) jiaRoutine();
	    	else if(index == 2) jianRoutine();
	    });
	    
   });
   function searchPoint(thiz) {
	    keyId = $(thiz).attr("data-id");
    	$(".teacherName").html($(thiz).attr("data-name"));
    	$("#search-content").hide();
    	$("#tab3").show();
		$(".sb-content").html('');
		$("#weui_search_input").val(null);
    	$('#tab3').tab({
			defaultIndex: 0,
			activeClass: "tab-blue "
		});
    	totalPage = 0, jiaPage = 0, jianPage = 0;
    	$("#totalList").html('');
    	$("#jiaList").html('');
    	$("#jianList").html('');
    	$('.loadData').removeClass("dropload-noData").addClass("dropload-hasData").html("点击加载更多数据...");
    	loadTotalPoints();
        totalRoutine();
   }
   function loadTotalPoints() {
	   $.ajax({
			url : basePath + "/ls/teacher/points/totalPoint",
			type : "post",
			dataType : "json",
			data : {
				keyId: keyId
			},
			async : false,
			success : function(data) {
				if(data != null) {
					//FIXME 这里我（huhekun）觉得录入的成绩应该自带负号，不需要再加
					$(".totalPoint").html((data.totalPoint > 0 ? "+" : "") + data.totalPoint);
					$(".termPoint").html((data.termPoint > 0 ? "+" : "") + data.termPoint);
					$(".monthPoint").html((data.monthPoint > 0 ? "+" : "") + data.monthPoint);
				} else {
					//使得每次换班级积分都会变
					$(".totalPoint").html(0);
					$(".termPoint").html(0);
					$(".monthPoint").html(0);
				}
			}, error:function(){
			}
		});
   }
   function totalRoutine() {
	   totalPage = totalPage + 1;
	   var params = {
			page: totalPage,
			rows: totalRows,
			keyId: keyId
	   }
	   loadRoutineList(params,"totalList");
   }
   function jiaRoutine() {
	   jiaPage = jiaPage + 1;
	   var params = {
			page: jiaPage,
			rows: jiaRows,
			keyId: keyId,
			scoreCompare: 1
	   }
	   loadRoutineList(params,"jiaList");
   }
   function jianRoutine() {
	   jianPage = jianPage + 1;
	   var params = {
			page: jianPage,
			rows: jianRows,
			keyId: keyId,
			scoreCompare: -1
	   }
	   loadRoutineList(params,"jianList");
   }
   function loadRoutineList(params, id) {
	   $.ajax({
			url : basePath + "/ls/teacher/points/routine/pageQuery",
			type : "post",
			data : params,
			dataType : "json",
			async : false,
			success : function(data) {
				if(data != null) {
					if(data.rows.length == 0 || params.page*params.rows >= data.total) {// 如果没有数据
	            		 $("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                 	 if(data.rows.length == 0) return;
	                }
					var html = "";
					for(var i in data.rows) {
						var itm = data.rows[i];
						html += '<a class="weui_cell" href="<%=basePath %>/ls/teacher/points/routine/detail/'+itm.id+'">\
							<div class="weui_cell_bd weui_cell_primary">\
							<h4 class="weui_media_title">'+itm.judgeType+'</h4>\
	                        <span class="point_score">'+(itm.score > 0 ? "+" : "")+itm.score+'</span>\
	                        <p class="weui_media_desc pt10">'+itm.judgeContent+'</p>\
	                        <p class="weui_media_desc">'+getTime(itm.judgeTime, "yyyy-MM-dd hh:mm")+'</p></div>\
						<span class="weui_cell_ft"></span></a>';
					}
					$("#" + id).append(html);
				}
			}, error:function(){
			}
		});
   	}
    var search = false;
	function queryItem(keyword) {
		if(!/^[\u4E00-\u9FA5]+$/.test(keyword)) return;
		if(search) return;
		search = true;
		$.ajax({
    		url: basePath + "/ls/teacher/manage/keyword",
    		type: 'POST',
    		dataType : "json",
    		data: {
    			teacherName: keyword
    		},
    		success: function(data) {
    			search = false;
    			if (data != null && data.length > 0) {
    				var html = "";
    				for(var i in data) {
    					var itm = data[i];
            			html += '<div onclick="searchPoint(this)" class="weui_cell" data-id="'+data[i].id+'" data-name="'+data[i].name+'">';
    					html += '<div class="weui_cell_bd weui_cell_primary"><p>' + itm.name + '</p>';
    					html += '</div></div>';
    				}
    				$(".sb-content").html(html);
    			}
    		},
    		error: function(data) {
    			alert("系统异常,请联系管理员");
    		}
    	});
   	}
</script>
</html>